//
//  Pet_RecordDetailViewController.swift
//  PetApp
//
//  Created by mac on 2023/10/13.
//  Copyright © 2023 Pet_. All rights reserved.
//

import UIKit

class Pet_RecordDetailViewController: BasicViewController {

    var model:InfoUtil.recordDta?{
        didSet{
            let str = "icon_" + (model?.type ?? "")
            self.iconImg.image = .init(named:str)
            self.nameL.text = model?.desc
            self.timeL.text = "Deadline \(model?.time ?? "")"
        }
    }
    let backV = UIView.init(frame: .zero)
    let iconImg = UIImageView.initImgView(img: "")
    private var nameL = UILabel.initV(.setTypeFace(16.Fit,type: .medium), text: "", textColor:titleColor)
    private var timeL = UILabel.initV(.setTypeFace(14,type: .medium), text: "", textColor:.white)
    private lazy var doneButton: UIButton = {
        let button = UIButton(type: .custom)
        button.titleLabel?.font = .setTypeFace(16.Fit,type: .medium)
        button.setTitleColor(mainColor, for: .normal)
        button.setTitle("Done", for: .normal)
        button.backgroundColor = .black
        button.layer.cornerRadius = 25
        return button
    }()
    private lazy var deleteButton: UIButton = {
        let button = UIButton(type: .custom)
        button.titleLabel?.font = .setTypeFace(16.Fit,type: .medium)
        button.setTitleColor(.black, for: .normal)
        button.setTitle("Delete the reminder", for: .normal)
        button.backgroundColor = .clear
        button.setImage(.init(named: "delete"), for: .normal)
        button.layer.cornerRadius = 25
        button.layer.borderWidth = 1
        button.layer.borderColor = UIColor.black.cgColor
        return button
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        title = "Reminder"
        view.subviews {
            backV.subviews {
                iconImg
                nameL
                timeL
            }
            doneButton
            deleteButton
        }
        backV.left(15.Fit).right(15.Fit).top(15.Fit + NavHeight).height(210.Fit)
        backV.backgroundColor = .init(white: 1, alpha: 0.3)
        backV.setAllCorners(corner: 15.Fit)
        
        iconImg.size(80.Fit).top(20.Fit)
        iconImg.centerHorizontally()
        
        nameL.left(15.Fit).right(20.Fit).height(40.Fit)
        nameL.Top == iconImg.Bottom + 10.Fit
        nameL.numberOfLines = 0
        nameL.textAlignment = .center

        timeL.textAlignment = .center
        timeL.backgroundColor = .color(hexString: "#8C21E8")
        timeL.Top == nameL.Bottom + 15.Fit
        timeL.height(25.Fit).width(145.Fit)
        timeL.centerHorizontally()
        
        doneButton.left(15.Fit).right(15.Fit).height(50)
        doneButton.Top == backV.Bottom + 30.Fit
        doneButton.addAct {
            if let model = self.model {
                Pet_RecordManager.shared.doneRecord(model)
            }
            self.navigationController?.popViewController(animated: true)
        }
        
        deleteButton.left(15.Fit).right(15.Fit).height(50)
        deleteButton.Top == doneButton.Bottom + 25.Fit
        deleteButton.titleEdgeInsets = .init(top: 0, left: 10, bottom: 0, right: 0)
        deleteButton.addAct {
            let view = DeleteReminder_View()
            view.DoneBlock = {
                if let model = self.model {
                    Pet_RecordManager.shared.removeRecord(model)
                }
                self.navigationController?.popViewController(animated: true)
            }
            let page = Pop_Up_Custom_View(config: PopUpViewConfig(view: view, size: CGSize(width: screenWidth-30.Fit, height: 405.Fit)))
            page.isCloseFromClean = false
            page.animatedPop()
        }
        
    }

}
